package cn.itsource.xhy.order.controller;

import cn.itsource.xhy.order.service.IOrderAdoptService;
import cn.itsource.xhy.order.service.IOrderProductService;
import cn.itsource.xhy.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/product")
public class OrderProductController {

    @Autowired
    private IOrderProductService orderProductService;

    @PostMapping
    public AjaxResult createOrder(@RequestBody Map<String,String> map, HttpServletRequest request){
        System.out.println(map);
        //{product_id=174, address_id=1, payment_way=AliPay}
        try {
            String result = orderProductService.createOrder(map,request);
            return AjaxResult.me().setResultObj(result);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }
}
